import time

from selenium.webdriver.common.by import By

from common.Untils import QESDriver


class MyQuestionBank:

    def __init__(self):
        self.url = "http://8.155.1.153:8081/repo/index"
        self.driver = QESDriver.driver
        self.driver.get(self.url)

    def GetMyQuestionBank(self):
        # 查找输入框并输入“111”
        self.driver.find_element(By.XPATH, '//*[@id="name"]').send_keys("111")
        # 查找“查询”并点击
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/form/div/div[3]/div/div/div[2]/div/div/div/div/div/div[2]/button').click()
        time.sleep(1.5)
        QESDriver.GetScreenShot()
        # 查找“重置”并点击
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/form/div/div[3]/div/div/div[2]/div/div/div/div/div/div[1]/button').click()

    # 新建题库
    def CreateNewQuestionBank(self):
        self.driver.find_element(By.XPATH,
                                     '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[1]/div/div[2]/div[1]/div/div[1]/button/span[2]').click()
        # 查找输入“题库名称”
        self.driver.find_element(By.CSS_SELECTOR, '#name').send_keys("自动化测试新建题库")
        time.sleep(1.5)
        # 查找输入“题库分类”
        self.driver.find_element(By.XPATH, '//*[@id="category"]').send_keys("自动化")
        # 查找输入“题库描述”
        self.driver.find_element(By.XPATH, '//*[@id="description"]').send_keys("自动化")
        QESDriver.GetScreenShot()
        # 返回
        self.driver.back()

    def TestManagement(self):
        # 试题管理
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/div/div/div/div/table/tbody/tr[2]/td[9]/div/div[3]/a').click()
        time.sleep(1.5)
        QESDriver.GetScreenShot()

#问题管理
class ProblemManagement:
    def __init__(self):
        self.url = "http://8.155.1.153:8081/repo/template"
        self.driver = QESDriver.driver
        self.driver.get(self.url)

    def GetProblemManagement(self):
        QESDriver.GetScreenShot()
        # 点击展开
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/form/div/div[5]/div/div/div[2]/div/div/div/div[2]/a').click()
        # 输入“单选”并搜索
        self.driver.find_element(By.XPATH, '//*[@id="name"]').send_keys("单选")
        time.sleep(1.5)
        QESDriver.GetScreenShot()
        # 点击“重置”并点击“编辑”
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/form/div/div[5]/div/div/div[2]/div/div/div/div[1]/div/div[1]/button').click()
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/div/div/div/div/table/tbody/tr[2]/td[10]/div/div/a').click()
        time.sleep(1.5)
        QESDriver.GetScreenShot()
        # 退出编辑
        self.driver.find_element(By.XPATH, '//*[@id="editor"]/div[1]/div[1]/div[2]/div/button[1]').click()

#我的笔记
class MyNotes:
    url = ""
    driver = ""

    def __init__(self):
        self.url = "http://8.155.1.153:8081/repo/book"
        self.driver = QESDriver.driver
        self.driver.get(self.url)

    def GetMyNotes(self):
        # 查找输入框并输入“一”“1”
        self.driver.find_element(By.XPATH, '//*[@id="name"]').send_keys("一")
        # 点击展开
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/form/div/div[4]/div/div/div[2]/div/div/div/div[2]/a').click()
        self.driver.find_element(By.XPATH, '//*[@id="note"]').send_keys("1")
        # 点击查询
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/form/div/div[4]/div/div/div[2]/div/div/div/div[1]/div/div[2]/button').click()
        time.sleep(0.5)
        QESDriver.GetScreenShot()
        # 点击重置并点击删除
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/form/div/div[4]/div/div/div[2]/div/div/div/div[1]/div/div[1]/button').click()
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/div/div/div/div/table/tbody/tr[1]/td[5]/div/div/a').click()
        # 出现二次确认截图并返回
        # self.driver.switch_to.alert.accept()
        # self.driver.find_element(By.XPATH,'/html/body/div[6]/div/div[2]/div/div[2]/div/div/div[2]/button[2]').click()
        time.sleep(0.5)
        QESDriver.GetScreenShot()
        self.driver.refresh()






